package de.fhaugsburg.games.boardgames.scrabble.io;



import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class TerminalUtils {

	public static final String MSG_DIR = System.getProperty("user.dir") + "/msg_dir/";
	public static final String SERVER_MSG = MSG_DIR + "servermsg.";
	public static final String INPUT_REQUEST = MSG_DIR + "inputreq.";
	public static final String INPUT_RESPONSE = MSG_DIR + "inputres.";
	
	
	
	
	
	
	/**
	 * writes UTF-8 String to specified File file
	 * @param file
	 * @param msg
	 * @throws IOException 
	 */
	public static void writeFile(File file, String msg) throws IOException{
	      DataOutputStream fileOut = new DataOutputStream(new FileOutputStream(file));
	      fileOut.writeUTF(msg);
	      fileOut.close();
	}
	
	
	/**
	 * reads UTF-8 String from file specified by File file
	 * @param file
	 * @return UTF-8 String
	 * @throws IOException
	 */
	public static String readFile(File file) throws IOException{
	      DataInputStream fileIn = new DataInputStream(new FileInputStream(file));
	      String fileString = fileIn.readUTF();
	      fileIn.close();
	      return fileString;
	}
	
	
	
}